package com.wang.code;

import java.util.TreeSet;
public class _7TreeSetTest {

	public static void main(String[] args) {
		
		TreeSet set = new TreeSet();
		set.add(2);
		set.add(3);
		set.add(5);
		set.add(6);
		set.add(1);
		set.add(1);
		set.add(2);
		set.clear();
		set.add("A");
		set.add("C");
		set.add("B");
		System.out.println(set);
		
		System.out.println("===================");
		Student1 stu1 = new Student1("a",12);
		Student1 stu2 = new Student1("a",12);
		Student1 stu8 = new Student1("a",12);
		Student1 stu3 = new Student1("bnm",43);
		Student1 stu4 = new Student1("bnm",123);
		
		Student1 stu5 = new Student1("qwe",34);
		Student1 stu6 = new Student1("qwe2",123);
		Student1 stu7 = new Student1("qweddd",255);
		
		set.add(stu1);
		set.add(stu2);
		set.add(stu3);
		set.add(stu4);
		set.add(stu5);
		set.add(stu6);
		set.add(stu7);
		set.add(stu8);
		System.out.println(set);
		
	}

}

class Student1 implements Comparable<Student1>{
	private String name;
	private double height;
	public Student1() {
	}
	public Student1(String name, double height) {
		super();
		this.name = name;
		this.height = height;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getHeight() {
		return height;
	}
	public void setHeight(double height) {
		this.height = height;
	}
	@Override
	public String toString() {
		return "[" + name + ", " + height + "]";
	}
	@Override
	public int compareTo(Student1 o) {
		if (this.name.length() > o.name.length()) {
			return 1;
		} else if (this.name.length() < o.name.length()){
			return -1;
		} else {
			if (this.height > o.height) { 
				return 1;
			} else if (this.height < o.height){
				return -1;
			} else {
				return 0;
			}
		}
	}
	
}
